<%@ include file="/WEB-INF/pages/common/taglibs.jsp" %>
<%@ include file="/WEB-INF/pages/common/checkpermission.jsp" %>
<%@ include file="/WEB-INF/pages/cases/case1/checkCase1Permission.jsp" %>
<codelookup:codeCollection id="deptList" codeType="DEPT_LIST"/>

<script type="text/javascript">
    function searchRecord() {
        $("td").removeClass("showErrorClass");
        submitForm("searchForm", "search.action");
        return false;

    }

    function addRecord() {
        submitForm("searchForm", "viewAdd.action");
    }

    function updateRecord(recordName) {
        var currentForm = document.forms["searchForm"];
        currentForm.elements["caseOneModel.selectId"].value = recordName;
        submitForm("searchForm", "view.action");
    }


    function deleteRecord() {
        if (!atLeastOneRecordChecked('searchFormDiv')) {
            alert('<s:text name="label.select.atleast.one.record"/>');
        } else {
            if (window.confirm('<s:text name="label.confirm.delete"/>')) {
                submitForm("searchForm", "delete.action");
            }
        }
    }

    function back() {
        submitForm("searchForm", "../clientSummary.action");
    }

</script>
<div id='searchFormDiv'>
    <s:form name="searchForm" action="">
        <s:hidden name="caseOneModel.selectId" value=""/>
        <table align="center" cellpadding="0" cellspacing="0" class="body_content full_width">
            <tr>
                <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
                    <img src='<c:url value="/images/body-icon_check.gif"/>' width="29" height="44">
                </td>
                <td valign="bottom" class="page_title_bg" width="96%"><span class="page_title"><s:text
                        name="label.case.select.title1"/></span></td>
            </tr>
            <tr>
                <td class="subcontent">&nbsp;</td>
                <td class="subcontent">
                    <table class="sectionBorder" width="100%">
                        <s:if test='#attr.user.userRole=="A"'>
                        <tr>
                            <td class="form_label_padded" width="10%" nowrap><s:text name='label.deptId'/></td>
                            <td class="form_label_padded" width="2%">:</td>
                            <td class="txtData" align="left">
                                <s:select list="#attr.deptList" name="searchTO.deptId" listKey="codeId"
                                          listValue="codeDesc" headerKey="0" headerValue=""/>
                            </td>
                        </tr>
                        </s:if>
                        <tr>
                            <td class="form_label_padded" width="10%" nowrap><s:text name='label.dateFrom'/></td>
                            <td class="form_label_padded" width="2%">:</td>
                            <td class="txtData" align="left">
                                <monitor:date name="searchTO.dateFrom"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="form_label_padded" width="10%" nowrap><s:text name='label.dateTo'/></td>
                            <td class="form_label_padded" width="2%">:</td>
                            <td class="txtData" align="left">
                                <monitor:date name="searchTO.dateTo"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="txtData" colspan="6">
                                <input type="button" class="button" value="<s:text name='label.search'/>"
                                       onclick="searchRecord();">
                                <input type="button" class="button" value="<s:text name='label.add'/>"
                                       onclick="addRecord();">
                                <s:if test='#attr.user.userRole=="A"'>
                                    <input type="button" class="button" value="<s:text name='label.delete'/>"
                                           onclick="deleteRecord();">
                                </s:if>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="6">
                                <display:table name="helper" form="searchForm" uid="row" action="search.action">
                                    <display:column titleKey="label.seq" width="3%">
                                        <s:property
                                                value="%{#attr.row_rowNum+(helper.pageNumber-1)*helper.objectsPerPage}"/>
                                    </display:column>
                                    <display:column width="2%">
                                        <s:checkbox name="resultList[%{#attr.row_rowNum-1}].selectId"
                                                    fieldValue="%{#attr.row.caseOneId}"/>
                                    </display:column>
                                    <display:column titleKey="label.deptId" sortable="true" sortProperty="DEPT_ID"
                                                    width="35%">
                                        <a href="javascript:updateRecord('<s:property value="%{#attr.row.caseOneId}"/>')">
                                            <codelookup:codeDesc codeType="DEPT_LIST" codeId="${row.deptId}"/>
                                        </a>
                                    </display:column>
                                    <display:column titleKey="label.caseone.name" sortable="true" sortProperty="NAME"
                                                    width="30%">
                                        <s:property value="%{#attr.row.name}"/>
                                    </display:column>
                                    <display:column titleKey="label.create.date" sortable="true"
                                                    sortProperty="CREATE_DATE" width="30%">
                                        <s:property value="%{#attr.row.createDt}"/>
                                    </display:column>
                                </display:table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td width="4%">&nbsp;</td>
                <td  class="txtData" align="left" width="96%">
                    <input type="button" class="button" value="<s:text name='label.back'/>" onclick="back();">
                </td>
            </tr>
        </table>   
    </s:form>
</div>
